﻿using AnQinFrameWorkAPI.Entity.Blog.DTO.BlogText;
using AnQinFrameWorkAPI.Entity.Blog.View.BlogText;
using AnQinFrameWorkAPI.Service.Blog;
using FrameWork.Entity;
using Microsoft.AspNetCore.Mvc;

namespace AnQinFrameWorkAPI.Controllers.Blog;

/// <summary>
///     博客文章API
/// </summary>
[Route("api/[controller]")]
[ApiController]
[ApiExplorerSettings(GroupName = "Blog")]
public class BlogTextController : ControllerBase
{
    // 业务服务接口
    private readonly BlogTextService _blogTextService;

    // 构造注入
    public BlogTextController(BlogTextService blogTextService)
    {
        _blogTextService = blogTextService;
    }

    /// <summary>
    ///     获取博客文章列表（分页）
    /// </summary>
    /// <param name="searchDTO">查询条件</param>
    [ProducesResponseType(typeof(BlogTextView), 200)]
    [HttpGet]
    public async Task<IActionResult> GetBlogTextList([FromQuery] BlogTextSearchDTO searchDTO)
    {
        var response = await _blogTextService.GetBlogTextList(searchDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     新增博客文章
    /// </summary>
    /// <param name="addDTO">文章数据</param>
    [HttpPost]
    public async Task<IActionResult> AddBlogText([FromBody] BlogTextAddDTO addDTO)
    {
        var response = await _blogTextService.AddBlogText(addDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     更新博客文章
    /// </summary>
    /// <param name="updateDTO">文章数据</param>
    [HttpPut]
    public async Task<IActionResult> PutBlogText([FromBody] BlogTextUpdateDTO updateDTO)
    {
        var response = await _blogTextService.PutBlogText(updateDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     删除博客文章
    /// </summary>
    /// <param name="deleteDTO">删除参数</param>
    [HttpDelete]
    public async Task<IActionResult> DeleteBlogText([FromBody] SingleIdDTO deleteDTO)
    {
        var response = await _blogTextService.DeleteBlogText(deleteDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     博客文章-审核通过
    /// </summary>
    /// <param name="idArrayDTO">参数</param>
    [HttpPost("Pass")]
    public async Task<IActionResult> PassBlogText([FromBody] IdArrayDTO idArrayDTO)
    {
        var response = await _blogTextService.PassBlogText(idArrayDTO);
        return StatusCode(response.Status, response);
    }

    /// <summary>
    ///     博客文章-审核不通过
    /// </summary>
    /// <param name="idArrayDTO">参数</param>
    [HttpPost("UnPass")]
    public async Task<IActionResult> UnPassBlogText([FromBody] IdArrayDTO idArrayDTO)
    {
        var response = await _blogTextService.UnPassBlogText(idArrayDTO);
        return StatusCode(response.Status, response);
    }
}